<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'send.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="js/ajax-pushlet-client.js"></script>
	
	<script type="text/javascript">
		PL._init();
		//PL.setDebug(true);
		PL.NV_P_MODE = 'p_mode=stream';
		
		//p_join_listen('/guoguo/myevent2');// 对于stream模式,不能用这种方式,要用下面的p_join();
		
		p_join();// 只有这一句的话,不会超时,如果再加上下面的这句超时的时候,接收方会接收不到数据
    	//p_listen('/guoguo/myevent2');// 这一句不行,必须要先p_join,这一句不是必须的
    	
	    function sendnews() {
	    	var msg = document.getElementById('mymsg').value;
	    	//alert(msg);
	    	// 广播消息
	    	p_publish('/guoguo/myevent2', 'key1', msg, 'key2','msg2');
	    	
	    }
    	
	    function onData(event) {
     	   alert("1" + event);
        }
	    
	</script>

  </head>
  
  <body>
    This is my JSP page. <br>
    <input type="text" id="mymsg"/>
	<input type="button" value="发消息" onclick="sendnews()" />
  </body>
</html>
